import { query } from './mySQLdb';

// 创建用户
export async function createEmailcode(email: string, passcode: string) {
    const sql = 'INSERT INTO logup_email (email, passcode) VALUES (?, ?)';
    const params = [email, passcode];
    try {
        const result = await query(sql, params);
        return { id: (result as any).insertId, email, passcode };
    } catch (error) {
        throw error;
    }
}

// 获取所有用户
export async function getAllUsers() {
    const sql = 'SELECT * FROM users_data';
    try {
        const users = await query(sql);
        return users;
    } catch (error) {
        throw error;
    }
}

// 根据 参数 获取用户
export async function getPassCodeByEmail(passQql: string, data: []) {
    const sql = passQql;
    const params = data;
    try {
        const result = await query(sql, params);
        return result;
    } catch (error) {
        throw error;
    }
}




// 删除用户
export async function deleteEmailcode(id) {
    const sql = 'DELETE FROM logup_email WHERE id = ?';
    const params = [id];
    try {
        await query(sql, params);
        return { id };
    } catch (error) {
        throw error;
    }
}